import axios from 'axios';
import type { RouteRecordNormalized } from 'vue-router';
import { UserState } from '@/store/modules/user/types';

export interface LoginData {
  username: string;
  password: string;
  captcha: string; // 验证码
}

export interface LoginRes {
  token: string;
}

// data: LoginData 才是提交的数据
// <是服务器返回的数据>
// 账号密码登录
export function login(data: LoginData) {
  return axios.post<LoginRes>('/api/user/login', data);
}

export function getUserInfo() {
  return axios.post<UserState>('/api/user/info');
}

export function getMenuList() {
  return axios.post<RouteRecordNormalized[]>('/api/user/menu');
}

// // 账号密码登录
// export function login(data: LoginData) {
//   return axios.post<LoginRes>('/api/user/login', data);
// }

// // 获取登录验证码
export function getCaptcha() {
  return axios.post('/login/captcha');
}

// 退出登录;
export function logout() {
  return axios.post('/login/logout');
}

// 获取所有用户
export function getAllUser(data: any) {
  return axios.get('/user/all', {
    params: data,
  });
}
